package com.tianji.remark.task;

import com.tianji.remark.service.ILikedRecordService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.List;

@Slf4j
@Component
@RequiredArgsConstructor
public class LikedTimesCheckTask {

    private static final List<String> BIZ_TYPES = List.of("QA", "NOTE");// 业务类型

    private static final int MAX_BIZ_SIZE = 30;// 每次取的最大数量, 防止一次往 mq 发太多消息

    private final ILikedRecordService likedRecordService;

    /**
     * 每 20 秒, 执行一次, 将 redis 中业务下面的某个业务点赞总数发送到mq
     */
    // @Scheduled(cron = "0/20 * * * * ?")
    @Scheduled(fixedDelay = 20000)
    public void checkLikedTimes() {
        for (String bizType : BIZ_TYPES) {
            likedRecordService.readLikedTimesAndSendMessage(bizType, MAX_BIZ_SIZE);
        }
    }
}
